
#include <stdio.h>
#include <sstream>
#include <iostream>
#include <iomanip>

#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "esp_log.h"
#include "sdkconfig.h"
#include "esp_mac.h"

#include "ConstDefine.hpp"

#define BLINK_GPIO GPIO_NUM_48

static uint8_t s_led_state = 0;

static void blink_led()
{
    /* Set the GPIO level according to the state (LOW or HIGH)*/
    gpio_set_level(BLINK_GPIO, s_led_state);
}

static void configure_led()
{
    LOG_INFO("configured to blink GPIO LED!");
    gpio_reset_pin(BLINK_GPIO);
    /* Set the GPIO as a push/pull output */
    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
}

extern "C" [[noreturn]] void app_main(void)
{
    uint8_t mac[8]{};
    int e = esp_efuse_mac_get_default(mac);
    LOG_INFO("default mac: %d %s", e, to_hex(mac, 6, ":").c_str());
    auto delay = 1 * 1000 / portTICK_PERIOD_MS;

    configure_led();
    while (true)
    {
        LOG_INFO("LED 状态: %d %s!",delay, s_led_state == true ? "ON" : "OFF");
        blink_led();
        s_led_state = !s_led_state;
        vTaskDelay(delay);
    }
}
